#include <iostream>
using namespace std;

int recursive_method(int x, int y)
{
    if ( y== 0) {
        return x;
    }
    else {
        return recursive_method(y, x % y);
    }
}

int non_recursive_method(int x, int y)
{
    while (y) {
        int tmp = y;
        y = x % y;
        x = tmp;

    }
    return x;
}

int main()
{
    int first, second;
    cin >> first >> second;
    cout << recursive_method(first, second) << endl;
    cout << non_recursive_method(first, second) << endl;
    return 0;
}
